﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Cheetah_Fast_Banking_App
{
    public partial class TransactionForm : Form
    {
        private Transaction _transaction;

        public string Description
        {
            get { return DescriptionTextBox.Text; }
            set { DescriptionTextBox.Text = value; }
        }

        public decimal Amount
        {
            get { return Decimal.Parse(AmountTextBox.Text); }
            set { AmountTextBox.Text = value.ToString(); }
        }

        public DateTime Date
        {
            get { return TransactionDateTime.Value; }
            set { TransactionDateTime.Value = value; }
        }

        public TransactionForm()
            : this(null)
        { }

        public TransactionForm(Transaction transaction)
        {
            InitializeComponent();
            this._transaction = transaction;
            LoadTransaction();
        }

        private void LoadTransaction()
        {
            if (this._transaction == null)
                return;

            this.Description = _transaction.Description;
            this.Date = _transaction.Date;
            this.Amount = _transaction.Amount;
        }

        public Transaction GetTransaction()
        {
            return _transaction;
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (_transaction == null)
            {
                _transaction = new Transaction(this.Description, this.Date, this.Amount);
            }
            else
            {
                _transaction.Description = this.Description;
                _transaction.Date = this.Date;
                _transaction.Amount = this.Amount;
            }

            this.DialogResult = DialogResult.OK;

            this.Hide();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
